package com.itheima.bos.web.action.base;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import com.itheima.bos.domain.base.Standard;
import com.itheima.bos.service.base.IStandardService;
import com.itheima.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;

public class StandardAction extends BaseAction<Standard>{
	
	//注入sevice
	@Autowired
	private IStandardService standardService;
	
	//添加操作
	@Action(value = "standard_sava", results = { @Result(name = "success", location = "/pages/base/standard.html", type = "redirect")})
	public String sava() {
		standardService.save(model);
		return SUCCESS;
	}
	
	//分页查询操作
	@Action(value="standard_pageQuery",results={@Result(name="success",type="json")})
	public String pageQuery(){
		//调用业务层，查询结果
		Pageable pageable=new PageRequest(page-1,rows);
		Page<Standard>pageData=standardService.findPageData(pageable);
		//将数据压进栈顶
		ActionContext.getContext().getValueStack().push(pageData);
		return SUCCESS;
	}
	//查询所有收派标准
	@Action(value="standard_findAll",results={@Result(name="success",type="json")})
	public String findAll(){
		//调用业务层查询所有标准
		List<Standard> standards= standardService.findAll();
		//将查询到的收派标准压进栈顶
		ActionContext.getContext().getValueStack().push(standards);
		return SUCCESS;
	}
	
}
